package java基础知识;

/**
 * @author coderFu
 * @create 2022/2/7
 * 懒汉式单例模式
 */
public class LazySingleObject {

    private static LazySingleObject LAZY_SINGLE_OBJECT = null;

    //此处锁住的是整个static方法，而不是当前对象。

    public static synchronized LazySingleObject getInstance(){
        if (LAZY_SINGLE_OBJECT == null){
            LAZY_SINGLE_OBJECT = new LazySingleObject();
        }
        return LAZY_SINGLE_OBJECT;
    }
}
